<?php
/*
+-----------------------------------------------------------------------------+
| $Id: *.php,v 1.* 2005/07/01 06:15:08 Bleakwind Exp $
| SnowStats
|         --- A Web Statistics Analysis for multiuser
| Copyright (c) 2003-2005 Weaverdream.com By Bleakwind
| http://www.weaverdream.com
+-----------------------------------------------------------------------------+
*/

include_once 'include/include.php';
include_once 'include/header.php';
?>

<table width="760" border="0" cellpadding="0" cellspacing="0" bgcolor="#5E94DD" align="center">
  <tr bgcolor="#5E94DD">
    <td width="200" align="center" valign="top" class="left_bg">
      <?include_once 'include/menu.php';?>
    </td>
    <td width="560" bgcolor="#FFFFFF" valign="top">

<?php
if(empty($_GET['act'])){//empty

if(isset($_GET['user']) && ($_GET['user'] != "")){
   $username        = check_username($_GET['user']);
   $file_config = $SETTING['dir_data'].$username."/".$SETTING['file_config'];
   if(!file_exists($file_config)){
       header("location:login.php?act=select&mes=".htmlentities(urlencode($LANGUAGE['login_select_nouser'])));
       exit;
   } else {
       $_SESSION['sess_select'] = $username;
   }
}

if(if_selectuser() == "y"){
?>
<table width="100%" border="0" cellspacing="0" cellpadding="3" align="center" bgcolor="#EBE9ED"><tr><td><img src="images/arrowright.gif" border=0 align="absmiddle"> <a href="index.php" target="_self"><font style="color:#000000;"><?php echo CONFIG_WEBSITE;?></font></a> &raquo; <?php echo $LANGUAGE['login_select'];?></td></tr></table>
<br>
<table width="95%" border="0" cellspacing="1" cellpadding="3" align="center" bgcolor="#5E94DD">
  <tr bgcolor="#EBE9ED">
    <td height="60" align="center">
      <?php echo sprintf($LANGUAGE['login_select_welcome'],"<font class=\"salient\">".$_SESSION['sess_select']."</font>");?>
    </td>
  </tr>
</table>
<br>
<?php
}elseif(if_userlogin() == "y"){
?>
<table width="100%" border="0" cellspacing="0" cellpadding="3" align="center" bgcolor="#EBE9ED"><tr><td><img src="images/arrowright.gif" border=0 align="absmiddle"> <a href="index.php" target="_self"><font style="color:#000000;"><?php echo CONFIG_WEBSITE;?></font></a> &raquo; <?php echo $LANGUAGE['login_login'];?></td></tr></table>
<br>
<table width="95%" border="0" cellspacing="1" cellpadding="3" align="center" bgcolor="#5E94DD">
  <tr bgcolor="#EBE9ED">
    <td height="60" align="center">
      <?php echo sprintf($LANGUAGE['login_login_welcome'],"<font class=\"salient\">".$_SESSION['sess_username']."</font>");?>
    </td>
  </tr>
</table>
<br>
<?php
}else{
   header("location:login.php?act=login");
}

}else{//empty

switch($_GET['act']){
case "select":
?>

<table width="100%" border="0" cellspacing="0" cellpadding="3" align="center" bgcolor="#EBE9ED"><tr><td><img src="images/arrowright.gif" border=0 align="absmiddle"> <a href="index.php" target="_self"><font style="color:#000000;"><?php echo CONFIG_WEBSITE;?></font></a> &raquo; <?php echo $LANGUAGE['login_select'];?></td></tr></table>
<br>
<table width="300" border="0" cellspacing="1" cellpadding="3" align="center" bgcolor="#FFFFFF">
<form action="login.php?act=saveselect" method="post" name="select">
<tr bgcolor="#5E94DD"><td align="center" class="right_title"><?php echo $LANGUAGE['login_select_explain'];?></td></tr>
<tr bgcolor="#EBE9ED"><td height="25" align="center"><?php echo $LANGUAGE['login_select_username'];?><input name="username" type="text" size="15" class="input" value="<?php echo $_SESSION['sess_select'];?>"></td></tr>
<tr bgcolor="#5E94DD"><td height="25" align="center"><input type="submit" value="<?php echo $LANGUAGE['login_submit'];?>" class="submit"> <input type="reset" value="<?php echo $LANGUAGE['login_reset'];?>" class="submit">
</td></tr></form></table>
<?php
break;

case "saveselect":
if(!isset($_POST['username']) || $_POST['username'] == ""){
   header("location:prompt.php?act=failed&mes=".htmlentities(urlencode($LANGUAGE['login_warning_empty'])));
   exit;
}
$username    = check_username($_POST['username']);
$file_config = $SETTING['dir_data'].$username."/".$SETTING['file_config'];
if(!file_exists($file_config)){
    header("location:prompt.php?act=failed&mes=".htmlentities(urlencode($LANGUAGE['login_select_nouser'])));
    exit;
} else {
    $_SESSION['sess_select'] = $username;
    header("location:prompt.php?act=succeed&url=general.php?user=".$_SESSION['sess_select']."&mes=".htmlentities(urlencode(sprintf($LANGUAGE['login_select_welcome'],"<font class=\"salient\">".$_SESSION['sess_select']."</font>"))));
    exit;
}

break;

case "login":?>

<table width="100%" border="0" cellspacing="0" cellpadding="3" align="center" bgcolor="#EBE9ED"><tr><td><img src="images/arrowright.gif" border=0 align="absmiddle"> <a href="index.php" target="_self"><font style="color:#000000;"><?php echo CONFIG_WEBSITE;?></font></a> &raquo; <?php echo $LANGUAGE['login_login'];?></td></tr></table>
<br>
<table width="300" border="0" cellspacing="1" cellpadding="3" align="center" bgcolor="#FFFFFF">
<form action="login.php?act=savelogin" method="post" name="login">
<tr bgcolor="#5E94DD"><td align="center" class="right_title"><?php echo $LANGUAGE['login_login_explain'];?></td></tr>
<tr bgcolor="#EBE9ED"><td height="25" align="center"><?php echo $LANGUAGE['login_login_username'];?><input name="username" type="text" size="15" class="input" value="<?php echo $_SESSION['sess_username'];?>"></td></tr>
<tr bgcolor="#EBE9ED"><td height="25" align="center"><?php echo $LANGUAGE['login_login_password'];?><input name="password" type="password" size="15" class="input"></td></tr>
<tr bgcolor="#5E94DD"><td height="25" align="center"><input type="submit" value="<?php echo $LANGUAGE['login_submit'];?>" class="submit"> <input type="reset" value="<?php echo $LANGUAGE['login_reset'];?>" class="submit">
</td></tr></form></table>
<?php
break;

case "savelogin":

if(!isset($_POST['username']) || $_POST['username'] == "" || !isset($_POST['password']) || $_POST['password'] == ""){
   header("location:prompt.php?act=failed&mes=".htmlentities(urlencode($LANGUAGE['login_warning_empty'])));
   exit;
}
$username    = check_username($_POST['username']);
$password    = check_password($_POST['password']);
$file_config = $SETTING['dir_data'].$username."/".$SETTING['file_config'];
if(!file_exists($file_config)){
   header("location:prompt.php?act=failed&mes=".htmlentities(urlencode($LANGUAGE['login_warning_noexists'])));
   exit;
}
include ($file_config);
if($CONFIGUSER['password'] != str_encrypt($password)){
   header("location:prompt.php?act=failed&mes=".htmlentities(urlencode($LANGUAGE['login_password_error'])));
   exit;
}else{
   $_SESSION['sess_username'] = $username;
   $_SESSION['sess_password'] = $password;
   $_SESSION['sess_select']   = $username;
   $_SESSION['sess_language'] = $CONFIGUSER['language'];
   header("location:prompt.php?act=succeed&url=general.php?user=".$_SESSION['sess_username']."&mes=".htmlentities(urlencode(sprintf($LANGUAGE['login_login_welcome'],"<font class=\"salient\">".$_SESSION['sess_username']."</font>"))));
   exit;
}

break;

case "logout":

unset($_SESSION['sess_username']);
unset($_SESSION['sess_password']);
header("location:prompt.php?act=succeed&url=index.php&mes=".htmlentities(urlencode($LANGUAGE['login_logout'])));
exit;

break;

default:
  header("location:prompt.php");
break;

}//swich
}//empty

echo "<br></td></tr></table>";
include_once 'include/footer.php';
?>